import { action, makeObservable, observable } from 'mobx';

type InitialData = {
    id?: number | string;
};
type ChangeFieldValue<T> = <F extends keyof T, V extends T[F]>(field: F, value: V) => void;

export const enum WithCommonStoreIndex {
    ID = 'id',
}

/**
 * `wrapper class` for common store
 * @props id system `userid`
 * @function changeFieldValue set the `field data` with the `input value`
 * @return `Class WithCommonStore`
 */
class WithCommonStore {
    @observable id?: string = undefined;

    constructor(initialData?: InitialData) {
        makeObservable(this);

        if (initialData?.id) this.id = initialData.id.toString() ?? undefined;
    }

    @action changeFieldValue: ChangeFieldValue<this> = (field, value) => {
        this[field] = value;
    };
}

export default WithCommonStore;
